package org.brisling.mobile.util;

import java.util.HashMap;
import java.util.Map;

public class MobileUtil {
	
	public MobileUtil(){};
	//获取单个随机数
	private Long generateId(int max){
		Long r = (long) Math.floor(Math.random()*1000);
		
		if(r<=max){
			return r;
		}else{
			return generateId(max);
		}
	}
	
	/**
	 * 获取max值范围内的times随机数集合
	 * @param max
	 * @param times
	 * @return
	 */
	public String[] generateFieldData(int max,int times){
		
		
		Map<String,String> map = new HashMap<String,String>();
		while(map.size()<times){
			Long id = generateId(max);
			if(id!=null){
				String sid = String.valueOf(id);
				map.put(sid, sid);
			}
		}
		
		String[] ret = new String[times];
		int cnt = 0;
		for(Map.Entry<String, String> entry:map.entrySet()){
			ret[cnt] = entry.getKey();
			cnt ++;
		}
		
		return ret;
	}
}
